"use strict"; // ==UserScript== // @name 69shuba auto 書簽 // @namespace Paul-16098 // @version 3.3.44.0 // @description 自動書籤,更改css,可以在看書頁(https://www.69shuba.com/txt/*/*)找到作者連結 // @author pl816098 // #region mate_match // #tag 69shux.com // @match https://69shux.com/txt/*/* // @match https://69shux.com/txt/*/end.html // @match https://69shux.com/book/*.htm* // #tag www.69shu.top // @match https://www.69shu.top/txt/*/* // @match https://www.69shu.top/txt/*/end.html // @match https://www.69shu.top/book/*.htm* // #tag www.69shu.cx // @match https://www.69shu.cx/txt/*/* // @match https://www.69shu.cx/txt/*/end.html // @match https://www.69shu.cx/book/*.htm* // #tag www.69shuba.pro // @match https://www.69shuba.pro/txt/*/* // @match https://www.69shuba.pro/txt/*/end.html // @match https://www.69shuba.pro/book/*.htm* // @match https://www.69shuba.pro/modules/article/bookcase.php // #endregion mate_match // @icon https://www.google.com/s2/favicons?sz=64&domain=69shuba.com // @grant window.close // @grant GM_addStyle // @grant GM_getValue // @grant unsafeWindow // @grant GM_registerMenuCommand // @grant GM_openInTab // @run-at document-idle // @license MIT // @supportURL https://github.com/Paul-16098/vs_code/issues/ // @homepageURL https://github.com/Paul-16098/vs_code/blob/main/js/userjs/README.md // ==/UserScript== /* ==UserConfig== config: is_close: title: 在結束頁時是否自動關閉 description: 在結束頁時是否自動關閉 type: checkbox default: true is_hook_alert: title: 是否劫持alert description: 是否劫持alert type: checkbox default: true auto_bookcase: title: 自動書籤 description: 自動書籤 type: checkbox default: true --- debug: debug_log: title: debug log description: debug log type: checkbox default: false ==/UserConfig== */ // https://github.com/scriptscat/scriptcat/issues/264 // ToDo 希望支持// @grant window.close var _a, _b, _c, _d, _e, _f, _g; var debug_log = GM_getValue("debug.debug_log", false); var is_close = GM_getValue("config.is_close", true); var auto_bookcase = GM_getValue("config.auto_bookcase", true); // @ts-expect-error var _unsafeWindow = (_a = unsafeWindow !== null && unsafeWindow !== void 0 ? unsafeWindow : globalThis) !== null && _a !== void 0 ? _a : window; //兼容 ios userscripts 的寫法 // @ts-expect-error var _GM_addStyle; if (typeof GM_addStyle !== "undefined") { _GM_addStyle = GM_addStyle; } else if (typeof GM !== "undefined" && typeof GM.addStyle !== "undefined") { _GM_addStyle = GM.addStyle; } else { _GM_addStyle = function (cssStr) { var styleEle = document.createElement("style"); styleEle.classList.add("_GM_addStyle"); styleEle.innerHTML = cssStr; document.head.appendChild(styleEle); return styleEle; }; } if (debug_log) { console.log("set func remove start"); } // @ts-expect-error function remove_ele() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } try { if (args && args.length > 0) { args.forEach(function (args) { if (debug_log) { console.log("args: ", args); console.log("document.querySelectorAll(args): ", document.querySelectorAll(args)); } if (document.querySelector(args)) { document.querySelectorAll(args).forEach(function (ele) { ele.remove(); }); } }); } else { throw new Error("fn remove error, args is not a array or args.length =< 0"); } } catch (e) { console.error(e); return [false, args, e]; } return [true, args]; } if (debug_log) { console.log("set func remove end\n", remove_ele); } // @ts-expect-error var pattern = { is_69shux: function (host) { if (host === void 0) { host = window.location.host; } if (host === "69shux.com") { return true; } else { return false; } }, is_bookshelf: function (href) { if (href === void 0) { href = window.location.href; } if (href === "https://www.69shuba.pro/modules/article/bookcase.php") { return true; } else { return false; } }, book: { get_aid: function (href) { if (href === void 0) { href = window.location.href; } var aid; try { // @ts-expect-error if (typeof bookinfo.articleid == undefined) { var _ = href.split("/"); aid = _[4]; } else { // @ts-expect-error aid = bookinfo.articleid; } return aid; } catch (e) { console.log(e); return undefined; } }, get_cid: function (href) { if (href === void 0) { href = window.location.href; } var cid; try { // @ts-expect-error if (typeof bookinfo.chapterid == undefined) { var _ = href.split("/"); cid = _[5]; } else { // @ts-expect-error cid = bookinfo.chapterid; } return cid; } catch (e) { console.log(e); return undefined; } }, pattern: /^(https?:\/\/)((www\.|)(69shuba|69xinshu|69shu|69shux)\.(com|pro|top|cx))\/txt\/[0-9]+\/(?!end)[0-9]+$/gm, is: function (href) { if (href === void 0) { href = window.location.href; } if (pattern.book.pattern.test(href)) { return true; } else { return false; } }, }, info: { pattern: /^(https?:\/\/)((www\.|)(69shuba|69xinshu|69shu|69shux)\.(com|pro|top|cx))\/book\/[0-9]+\.htm$/gm, is: function (href) { if (href === void 0) { href = window.location.href; } if (pattern.info.pattern.test(href)) { return true; } else { return false; } }, }, end: { pattern: /^(https?:\/\/)((www\.|)(69shuba|69xinshu|69shu|69shux)\.(com|pro|top|cx))\/txt\/[0-9]+\/end\.html$/gm, is: function (href) { if (href === void 0) { href = window.location.href; } if (pattern.end.pattern.test(href) || pattern.info.pattern.test(href)) { return true; } else { return false; } }, }, next_is_end: { is: function () { try { var url_1; var ele_1 = document.querySelector("div.page1 > a:nth-child(4)"); if (ele_1 !== (undefined || null)) { if (ele_1.href !== (undefined || null)) { url_1 = ele_1.href; } } else { console.error("網頁未載入完成"); return undefined; } } catch (e) { console.error(e); return undefined; } if (pattern.end.pattern.test(url)) { return true; } else { return false; } }, }, }; // @ts-expect-error var ele = []; if (pattern.book.is()) { if (debug_log) { console.log("book"); } if (debug_log) { console.log("_GM_addStyle start"); } _GM_addStyle("#title {\n font-size: large;\n font-weight: bold;\n color: #000;\n }\n \n .container {\n margin: 0px !important;\n min-height: 0px !important;\n width: 100% !important;\n max-width: none !important;\n }\n \n .mybox {\n padding: 0px;\n margin: 0px;\n }\n "); if (debug_log) { console.log("_GM_addStyle end"); } if (debug_log) { console.log("set ele start\n", ele); } ele = [ ".mytitle", ".top_Scroll", "#pagefootermenu", "body > div.container > div > div.yueduad1", "#goTopBtn", "#pageheadermenu", "body > div.container > div.yuedutuijian.light", ]; if (debug_log) { console.log("set ele end\n", ele); } if (debug_log) { console.log("remove(ele) start"); var remove_return = remove_ele(ele); console.log("remove(ele) end\n", remove_return); } else { remove_ele(ele); } if (auto_bookcase) { (_b = document.querySelector("#a_addbookcase")) === null || _b === void 0 ? void 0 : _b.click(); } else if (debug_log) { console.log("auto_bookcase !== true"); } var author = void 0; // @ts-expect-error if (typeof bookinfo.author === "string") { // @ts-expect-error author = bookinfo.author; // 網站原有的變量 } else { // 如果變量不存在 author = (_e = (_d = (_c = document .querySelector("body > div.container > div.mybox > div.txtnav > div.txtinfo.hide720 > span:nth-child(2)")) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim().split(" ")[1]) !== null && _e !== void 0 ? _e : "undefined"; } var aElement = document.createElement("a"); aElement.href = "".concat(window.location.origin, "/modules/article/author.php?author=").concat(author); aElement.textContent = author; aElement.style.color = "#007ead"; var spanElement = document.querySelector("body > div.container > div.mybox > div.txtnav > div.txtinfo.hide720 > span:nth-child(2)"); spanElement.textContent = spanElement.textContent.trim().split(" ")[0]; spanElement.appendChild(aElement); var title = document.querySelector("body > div.container > div.mybox > div.tools"); // 創建新的 元素 var link = document.createElement("a"); // 設置 元素的內容為 bookinfo.articlename // @ts-expect-error link.innerHTML = bookinfo.articlename; // 添加 元素的類名為 "userjs_add" link.classList.add("userjs_add"); // 設置 元素的 id 為 "title" link.id = "title"; // 設置 元素的 href // @ts-expect-error link.href = "".concat(window.location.origin, "/book/").concat(bookinfo.articleid, ".htm"); // 將 元素插入到 title 的父元素中 (_f = title.parentNode) === null || _f === void 0 ? void 0 : _f.replaceChild(link, title); } if (pattern.info.is()) { if (debug_log) { console.log("info"); } document.querySelector("body > div.container > ul > li.col-8 > div:nth-child(2) > ul > li:nth-child(2) > a").click(); document.querySelector("body > div.container > ul > li.col-8 > div:nth-child(1) > div > div.booknav2 > p:nth-child(2) > a").style.color = "#007ead"; document.querySelector("body > div.container > ul > li.col-8 > div:nth-child(1) > div > div.booknav2 > p:nth-child(3) > a").style.color = "#007ead"; } if (pattern.end.is()) { if (debug_log) { console.log("end"); } if (is_close) { window.close(); } } if (pattern.next_is_end.is()) { if (debug_log) { console.log("next_is_end"); } document.addEventListener("keydown", function (e) { if (!e.repeat) { switch (true) { case e.key === "ArrowRight": { if (debug_log) { console.log('(e.key === "ArrowRight") === true'); } if (auto_bookcase) { document.querySelector("#a_addbookcase").click(); } else if (debug_log) { console.log("auto_bookcase !== true"); } if (is_close) { window.close(); } break; } default: { if (debug_log) { console.log("e: ", e); } break; } } } }); (_g = document.querySelector("body > div.container > div.mybox > div.page1 > a:nth-child(4)")) === null || _g === void 0 ? void 0 : _g.addEventListener("click", function () { var _a; if (debug_log) { console.log("click"); } if (auto_bookcase) { (_a = document.querySelector("#a_addbookcase")) === null || _a === void 0 ? void 0 : _a.click(); } else if (debug_log) { console.log("auto_bookcase !== true"); } if (is_close) { window.close(); } }); } if (pattern.is_bookshelf()) { var n_1 = 0; var updata_url_1; var block_1 = false; var block_aid_list_1 = GM_getValue("Block_cid_list", []); var block_aid_list_n_1 = 0; var all_updata_label = document.querySelectorAll(".newbox2 h3 label"); all_updata_label.forEach(function (up_data_label) { n_1++; var url = Array.from(up_data_label.parentNode.parentNode.parentNode.parentNode.querySelectorAll(".newright > a.btn.btn-tp"))[0].href; var url_aid = new URLSearchParams(url).get("aid"); block_aid_list_1.forEach(function (l_aid) { if (l_aid == "*") { block_aid_list_n_1++; block_1 = true; return; } if (l_aid == url_aid) { block_aid_list_n_1++; block_1 = true; return; } }); if (block_1 === false) { updata_url_1.push(url); } }); GM_registerMenuCommand("".concat(n_1 === 0 ? "沒有" : "\u6709".concat(n_1, "\u500B"), "\u66F4\u65B0").concat(n_1 === 0 ? "" : block_aid_list_n_1 === 0 ? ",點擊全部打開" : ",\u9EDE\u64CA\u6253\u958B".concat(n_1 - block_aid_list_n_1, "\u500B")), function () { updata_url_1.forEach(function (url) { GM_openInTab(url); }); }); } if (GM_getValue("config.is_hook_alert", true)) { var _alert_1 = alert; _unsafeWindow.alert = function () { var message = []; for (var _i = 0; _i < arguments.length; _i++) { message[_i] = arguments[_i]; } var blockade = [["添加成功"], ["删除成功!"]]; var r = false; var n = 0; blockade.forEach(function (blockade_ele) { n++; if (JSON.stringify(message) === JSON.stringify(blockade_ele)) { console.log("not alert", message); r = true; } }); if (r === false) { if (debug_log) { console.log("alert", message); } _alert_1.apply(void 0, message); } }; } //# sourceMappingURL=69shuba%20auto%20%E6%9B%B8%E7%B0%BD.user.js.map